package com.xq.jltx.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.xq.jltx.greendaopro.R;
import com.xq.jltx.utils.FragmentUtils;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2016/07/15.
 */
public class MainFragment extends Fragment implements View.OnClickListener{
    private Button addBtn;
    private Button modefyDelBtn;
    private Button searchBtn;
    private Button updateBtn;

    public MainFragment() {
        super();
    }

    public static MainFragment newInstance(){
        MainFragment mainFragment = new MainFragment();
        return mainFragment;
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.main_fragment_layout,container,false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        assignView(view);
        addBtn.setOnClickListener(this);
        modefyDelBtn.setOnClickListener(this);
        searchBtn.setOnClickListener(this);
        updateBtn.setOnClickListener(this);
    }

    private void assignView(View view){
        addBtn = (Button)view.findViewById(R.id.add_btn);
        modefyDelBtn = (Button)view.findViewById(R.id.modefy_btn);
        searchBtn = (Button)view.findViewById(R.id.search_btn);
        updateBtn = (Button)view.findViewById(R.id.update_btn);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.add_btn:
                AddFragment addFragment = AddFragment.newInstance();
                FragmentUtils.openReplaceNextFragment(getFragmentManager(),addFragment,AddFragment.class.getSimpleName());
                break;
            case R.id.modefy_btn:
                ModefyFragment modefyFragment = ModefyFragment.newInstance();
                FragmentUtils.openReplaceNextFragment(getFragmentManager(),modefyFragment,ModefyFragment.class.getSimpleName());
                break;
            case R.id.search_btn:
                SearchFragment searchFragment = SearchFragment.newInstance();
                FragmentUtils.openReplaceNextFragment(getFragmentManager(),searchFragment,SearchFragment.class.getSimpleName());
                break;
            case R.id.update_btn:
                UpdateFragment updateFragment = UpdateFragment.newInstance();
                FragmentUtils.openReplaceNextFragment(getFragmentManager(),updateFragment,UpdateFragment.class.getSimpleName());
                break;
            default:
        }
    }


}
